/***************************************************************************
 *   Copyright (C) 2008 by						   *
 *          Ali Abdou							   *
 *          Camille Gallet						   *
 *          Rémy Hubscher						   *
 *          Regis Strub							   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef __GameEngine_HPP
#define __GameEngine_HPP

#include <QObject>
#include "Moving.hpp"

class PrologEngine;
class Player;
class PlayerIA;
class GameFrame;

class Plateau;

class GameEngine : public QObject
{
    Q_OBJECT

    public: 
  		enum player {BLUE=1, RED=2}; // Player Definition
        enum box {EMPTY=-1,SQUARE_ONLY=0,SQUARE_BLUE=1,SQUARE_RED=2};//state of a box from the gameboard
		static GameEngine * getInstance();
        void connecting(PrologEngine* pl, GameFrame* gf);

        bool jouer();
    private:
        Player * p1;
        Player * p2;
        Player * currentPlayer;
        GameEngine();
        static QVector<Plateau> coups;
        static unsigned int currentPos;
        static GameEngine * instance;
        void readConf();
        static GameEngine::box board[9];
    
    
    signals:
        void newBoard(int *);
        void jouerCoup(GameEngine::box*, Moving&,GameEngine::player);
        void gameOver(bool);
     	void coupForward(bool& ok,Moving &m, GameEngine::box* plateau, GameEngine::player p);
public slots:
	//void recupIAMove(Moving &m);
        void newGame();
	void revertCoup();
        void changeConf(QString p1Name, QString p2Name, bool p1Human, bool p2Human);
	void nextCoup();
	void recupMouseMove(Moving &m);
	void forwardCoup(bool& ok,Moving &m, GameEngine::box* plateau);
};

class Plateau{
    private:
	GameEngine::box p[9];

    public:
        Plateau(){};//for QVector
        Plateau(GameEngine::box *);
        GameEngine::box operator[](int i) const;
        GameEngine::box* getPlateau();
};


#endif
